package com.guigu.common.controller;


import com.guigu.common.pojo.SysUsers;

import com.guigu.common.vo.UserVo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;


@Controller
public class LoginController {


    @RequestMapping("/login")
    @ResponseBody
    public boolean login(@RequestBody UserVo userVo) {
        try {
            Subject subject = SecurityUtils.getSubject();
            UsernamePasswordToken token = new UsernamePasswordToken(userVo.getLoginId(), userVo.getPassword());
            subject.login(token);
            if ( "".equals(userVo.getCheckbox()) && userVo.getCheckbox()!=null) {
                token.setRememberMe(true);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }

        return true;
    }
    @RequestMapping("/SysUser/queryUser")
    @ResponseBody
    public SysUsers queryUser(){

        Subject subject = SecurityUtils.getSubject();
        SysUsers user1 = (SysUsers) subject.getSession().getAttribute("user");
        return user1;

    }


}
